package com.kevin.springboot.demos.utils;

import com.kevin.springboot.demos.exception.ServiceException;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

/**
 * 时间工具类
 * @author: wangyong
 * @date: 2019/8/17 13:14
 */
public class DateUtil {

	public static final String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";

	public static final String YYYYMMDD = "yyyyMMdd";

	public static String getDateTimeStr(Date date,String pattern){
		LocalDateTime localDateTime = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
		return DateTimeFormatter.ofPattern(pattern).format(localDateTime);
	}

	public static String getDateStr(Date date,String pattern){
		LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
		return DateTimeFormatter.ofPattern(pattern).format(localDate);
	}
}
